home *** CD-ROM | disk | FTP | other *** search
- import java.applet.Applet;
- import java.awt.Canvas;
- import java.awt.Color;
- import java.awt.Component;
- import java.awt.Dimension;
- import java.awt.Font;
- import java.awt.FontMetrics;
- import java.awt.Graphics;
- import java.awt.Image;
- import java.awt.image.ImageObserver;
-
- public class MarqueeCanvas2 extends Canvas implements Runnable {
- int speed = 100;
- String message;
- int currentX;
- int currentY;
- int theIncrementX = -1;
- int theIncrementY;
- Color bkColor;
- Color fontColor;
- Font font;
- boolean north = false;
- boolean east = false;
- boolean south = false;
- boolean west = false;
- Image bkImage;
- Image image;
- int theIncrement;
- Thread theThread;
- Image osImage;
- Graphics osg;
-
- public MarqueeCanvas2(Applet var1, int var2) {
- this.GetParameters(var1, var2);
- }
-
- void GetParameters(Applet var1, int var2) {
- String var3 = var1.getParameter("marqueeMessage" + var2);
- this.message = AppletParam2.GetString(var3, "");
- var3 = var1.getParameter("marqueeSpeed" + var2);
- this.speed = AppletParam2.GetInt(var3, 100);
- var3 = var1.getParameter("marqueeIncrement" + var2);
- this.theIncrement = AppletParam2.GetInt(var3, 1);
- var3 = var1.getParameter("marqueeBkColor" + var2);
- this.bkColor = AppletParam2.GetColor(var3, (Color)null);
- if (this.bkColor != null) {
- ((Component)this).setBackground(this.bkColor);
- }
-
- var3 = var1.getParameter("marqueeFont" + var2);
- this.font = AppletParam2.GetJavaFont(var3);
- var3 = var1.getParameter("marqueeFontColor" + var2);
- this.fontColor = AppletParam2.GetColor(var3, Color.red);
- var3 = var1.getParameter("marqueeBkImage" + var2);
- this.bkImage = var1.getImage(var1.getCodeBase(), var3);
- var3 = var1.getParameter("marqueeImage" + var2);
- this.image = var1.getImage(var1.getCodeBase(), var3);
- var3 = var1.getParameter("marqueeDirection" + var2);
- String var4 = AppletParam2.GetString(var3, "West");
- if (var4 == null) {
- var4 = "West";
- }
-
- this.SetDirection(var4);
- }
-
- public void Start() {
- this.theThread = new Thread(this);
- this.theThread.start();
- }
-
- public void Stop() {
- this.theThread.stop();
- this.theThread = null;
- }
-
- public void SetDirection(String var1) {
- if (var1.compareTo("East") == 0) {
- this.theIncrementX = this.theIncrement;
- this.theIncrementY = 0;
- this.east = true;
- } else if (var1.compareTo("North") == 0) {
- this.theIncrementX = 0;
- this.theIncrementY = -this.theIncrement;
- this.north = true;
- } else if (var1.compareTo("South") == 0) {
- this.theIncrementX = 0;
- this.theIncrementY = this.theIncrement;
- this.south = true;
- } else {
- this.theIncrementX = -this.theIncrement;
- this.theIncrementY = 0;
- this.west = true;
- }
- }
-
- public void update(Graphics var1) {
- if (this.osImage == null) {
- this.osImage = ((Component)this).createImage(((Component)this).size().width, ((Component)this).size().height);
- this.osg = this.osImage.getGraphics();
- }
-
- this.osg.setFont(this.font);
- FontMetrics var2 = this.osg.getFontMetrics();
- int var3 = var2.stringWidth(this.message);
- int var4 = var2.getHeight();
- this.osg.setColor(((Component)this).getBackground());
- this.osg.fillRect(0, 0, ((Component)this).size().width, ((Component)this).size().height);
- if (this.bkImage != null) {
- int var5 = this.bkImage.getWidth(this);
- int var6 = this.bkImage.getHeight(this);
- int var7 = ((Component)this).size().width / var5;
- int var8 = ((Component)this).size().height / var6;
- ++var7;
- ++var8;
-
- for(int var9 = 0; var9 < var8; ++var9) {
- for(int var10 = 0; var10 < var7; ++var10) {
- this.osg.drawImage(this.bkImage, var10 * var5, var9 * var6, this);
- }
- }
- }
-
- if (this.west) {
- if (this.message.length() > 0) {
- this.currentY = ((Component)this).size().height / 2 + var4 / 4;
- if (this.currentX <= -var3) {
- this.currentX = ((Component)this).size().width;
- }
-
- this.osg.setColor(this.fontColor);
- this.osg.drawString(this.message, this.currentX, this.currentY);
- }
-
- if (this.image != null) {
- this.currentY = ((Component)this).size().height / 2 - this.image.getHeight(this) / 2;
- if (this.currentX <= -this.image.getWidth(this)) {
- this.currentX = ((Component)this).size().width;
- }
-
- this.osg.drawImage(this.image, this.currentX, this.currentY, this);
- }
- } else if (this.east) {
- if (this.message.length() > 0) {
- this.currentY = ((Component)this).size().height / 2 + var4 / 4;
- if (this.currentX >= ((Component)this).size().width) {
- this.currentX = -var3;
- }
-
- this.osg.setColor(this.fontColor);
- this.osg.drawString(this.message, this.currentX, this.currentY);
- }
-
- if (this.image != null) {
- this.currentY = ((Component)this).size().height / 2 - this.image.getHeight(this) / 2;
- if (this.currentX > ((Component)this).size().width) {
- this.currentX = -this.image.getWidth(this);
- }
-
- this.osg.setColor(this.fontColor);
- this.osg.drawImage(this.image, this.currentX, this.currentY, this);
- }
- } else if (this.north) {
- if (this.message.length() > 0) {
- this.currentX = ((Component)this).size().width / 2 - var3 / 2;
- if (this.currentY == 0) {
- this.currentY = ((Component)this).size().height + var4;
- }
-
- this.osg.setColor(this.fontColor);
- this.osg.drawString(this.message, this.currentX, this.currentY);
- }
-
- if (this.image != null) {
- this.currentX = ((Component)this).size().width / 2 - this.image.getWidth(this) / 2;
- if (this.currentY <= -this.image.getHeight(this)) {
- this.currentY = ((Component)this).size().height;
- }
-
- this.osg.drawImage(this.image, this.currentX, this.currentY, this);
- }
- } else if (this.south) {
- if (this.message.length() > 0) {
- this.currentX = ((Component)this).size().width / 2 - var3 / 2;
- if (this.currentY == ((Component)this).size().height + var4) {
- this.currentY = 0;
- }
-
- this.osg.setColor(this.fontColor);
- this.osg.drawString(this.message, this.currentX, this.currentY);
- }
-
- if (this.image != null) {
- this.currentX = ((Component)this).size().width / 2 - this.image.getWidth(this) / 2;
- if (this.currentY > ((Component)this).size().height) {
- this.currentY = -this.image.getHeight(this);
- }
-
- this.osg.drawImage(this.image, this.currentX, this.currentY, this);
- }
- }
-
- this.currentX += this.theIncrementX;
- this.currentY += this.theIncrementY;
- var1.drawImage(this.osImage, 0, 0, (ImageObserver)null);
- }
-
- public Dimension minimumSize() {
- return new Dimension(10, 10);
- }
-
- public Dimension preferredSize() {
- return new Dimension(10, 10);
- }
-
- public synchronized void reshape(int var1, int var2, int var3, int var4) {
- super.reshape(var1, var2, var3, var4);
- this.osImage = null;
- this.osg = null;
- }
-
- public void run() {
- try {
- while(true) {
- ((Component)this).repaint();
- Thread.sleep((long)this.speed);
- }
- } catch (InterruptedException var1) {
- }
- }
- }
-